package i.i.myapplication.controller;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import i.i.myapplication.R;

public class WeChatAdapter extends RecyclerView.Adapter<WeChatAdapter.ViewHolder> {

    private final Context context;
    private final List<Integer> imageResIds;  // 改为 List<Integer>
    private final List<String> titles;        // 改为 List<String>
    private final List<String> descriptions;  // 改为 List<String>

    public WeChatAdapter(Context context, List<Integer> imageResIds, List<String> titles, List<String> descriptions) {
        this.context = context;
        this.imageResIds = imageResIds;
        this.titles = titles;
        this.descriptions = descriptions;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.wechat_item_layout, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.imageView.setImageResource(imageResIds.get(position));
        holder.titleTextView.setText(titles.get(position));
        holder.dateTextView.setText(descriptions.get(position));
    }

    @Override
    public int getItemCount() {
        return Math.min(imageResIds.size(), Math.min(titles.size(), descriptions.size()));
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView titleTextView;
        TextView dateTextView;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.imageView);
            titleTextView = itemView.findViewById(R.id.titleTextView);
            dateTextView = itemView.findViewById(R.id.dateTextView);
        }
    }
}

